/**
 * 提现订单管理初始化
 */
var WithdrawOrder = {
    id: "WithdrawOrderTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
WithdrawOrder.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
          
            {title: '订单号', field: 'outTradeNo', visible: true, align: 'center', valign: 'middle'},
            {title: '账户名', field: 'accountName', visible: true, align: 'center', valign: 'middle'},
            {title: '金额', field: 'amount', visible: true, align: 'center', valign: 'middle',formatter:"amountFormatter"},
            {title: '手续费', field: 'chargeAmount', visible: true, align: 'center', valign: 'middle',formatter:"amountFormatter"},
            {title: '提交时间', field: 'submitTime', visible: true, align: 'center', valign: 'middle'},
            {title: '手机号', field: 'tel', visible: true, align: 'center', valign: 'middle'},
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter:"statusFormatter"},
            {title: '响应码', field: 'retCode', visible: true, align: 'center', valign: 'middle'},
            {title: '描述', field: 'errMsg', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
         
    ];
};

function statusFormatter(value, row, index){
	if(value==0){
		return "已创建";
	}else if(value==1){
		return "提交成功";
	}else if(value==2){
		return "打款中";
	}else if(value==3){
		return "打款成功";
	}else if(value==4){
		return "打款失败";
	}
}

function amountFormatter(value, row, index){
	if(value==null || value==''){
		return "0.00";
	}else{
		return parseFloat(value).toFixed(2);
	}
}

/**
 * 检查是否选中
 */
WithdrawOrder.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        WithdrawOrder.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加提现订单
 */
WithdrawOrder.openAddWithdrawOrder = function () {
    var index = layer.open({
        type: 2,
        title: '添加提现订单',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/withdrawOrder/withdrawOrder_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看提现订单详情
 */
WithdrawOrder.openWithdrawOrderDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '提现订单详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/withdrawOrder/withdrawOrder_update/' + WithdrawOrder.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除提现订单
 */
WithdrawOrder.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/withdrawOrder/delete", function (data) {
            Feng.success("删除成功!");
            WithdrawOrder.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("withdrawOrderId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 订单同步
 */
WithdrawOrder.orderSyn = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/withdrawOrder/syn", function (data) {
            Feng.success("同步成功!");
            WithdrawOrder.table.refresh();
        }, function (data) {
            Feng.error("同步失败!" + data.responseJSON.message + "!");
        });
        ajax.set("withdrawOrderId",this.seItem.id);
        ajax.start();
    }
};



/**
 * 查询参数
 */
WithdrawOrder.formParams = function() {
    var queryData = {};
    queryData['accountName'] = $("#accountName").val();
    queryData['accountNo'] = $("#accountNo").val();
    queryData['outTradeNo'] = $("#outTradeNo").val();
    queryData['status'] = $("#status").val();

    return queryData;
}

/**
 * 查询提现帐号列表
 */
WithdrawOrder.search = function () {
	WithdrawOrder.table.refresh({query: WithdrawOrder.formParams()});
};


$(function () {
	var defaultColunms = WithdrawOrder.initColumn();
    var table = new BSTable(WithdrawOrder.id, "/withdrawOrder/list", defaultColunms);
    table.setPaginationType("server");//服务器端分页
    table.setQueryParams(WithdrawOrder.formParams());
    WithdrawOrder.table = table.init();
	   
});
